package ch.selise.archtool.lib;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;

class House extends ArrayList<HouseUnit> {
}
class Word extends House {
}
class PPT extends House {
}
class Excel extends House {
}
class HouseUnit {
  private String s;
  public HouseUnit(String s) {
    this.s = s;
  }
  public String toString() {
    return s;
  }
}
class Wall extends HouseUnit {
  public Wall(String s) {
    super(s);
  }
}
class Door extends HouseUnit {
  public Door(String s) {
    super(s);
  }
}
class Basement extends HouseUnit {
  public Basement(String s) {
    super(s);
  }
}
class ProductBuilder {
  public void buildBase() {
  }
  public void addHouseUnit(HouseUnit item) {
  }
  public House getFinishedProduct() {
    return null;
  }
}
class OfficeBuilder extends ProductBuilder {
  private Word b;
  public void buildBase() {
    System.out.println("Building word framework");
    b = new Word();
  }
  public void addHouseUnit(HouseUnit chapter) {
    System.out.println("Adding word page " + chapter);
    b.add(chapter);
  }
  public House getFinishedProduct() {
    return b;
  }
}
class DuplexHouseBuilder extends ProductBuilder {
  private PPT m;
  public void buildBase() {
    System.out.println("Building PPT");
    m = new PPT();
  }
  public void addHouseUnit(HouseUnit article) {
    System.out.println("Adding slide" + article);
    m.add(article);
  }
  public House getFinishedProduct() {
    return m;
  }
}
class MultiStoredBuilder extends ProductBuilder {
  private Excel w;
  public void buildBase() {
    System.out.println("Building Excel");
    w = new Excel();
  }
  public void addHouseUnit(HouseUnit webItem) {
    System.out.println("Adding workbook" + webItem);
    w.add(webItem);
  }
  public House getFinishedProduct() {
    return w;
  }
}
class BuilderDirector {
  private ProductBuilder mb;
  public BuilderDirector(ProductBuilder mb) {
    this.mb = mb; 
  }
  public House produceMedia(List input) {
    mb.buildBase();
    for (Iterator it = input.iterator(); it.hasNext();)
      mb.addHouseUnit((HouseUnit) it.next());
    return mb.getFinishedProduct();
  }
};
public class BuildOfficeDemo {
  public static void main(String[] args) {
    List input = Arrays.asList(new HouseUnit[] { new HouseUnit("item1"), new HouseUnit("item2"),
        new HouseUnit("item3"), new HouseUnit("item4"), });
    BuilderDirector buildBook = new BuilderDirector(new OfficeBuilder());
    House word = buildBook.produceMedia(input);
    String result = "word: " + word;
    System.out.println(result);
    BuilderDirector buildMagazine = new BuilderDirector(new DuplexHouseBuilder());
    House ppt = buildMagazine.produceMedia(input);
    result = "PPT: " + ppt;
    System.out.println(result);
    BuilderDirector buildWebSite = new BuilderDirector(new MultiStoredBuilder());
    House excel = buildWebSite.produceMedia(input);
    result = "Excel: " + excel;
    System.out.println(result);
  }
}

